part of 'component.dart';

class UITextField extends StatelessWidget {
  const UITextField({
    Key? key,
    this.prefixIcon,
    this.suffixIcon,
    required this.hintText,
    this.controller,
    this.obscureText,
    this.maxLength,
    this.height,
    this.prefixWidth,
    this.backgroundColor,
    this.keyboardType,
    this.inputFormatters,
    this.borderRadius,
    this.border,
    this.align = TextAlignVertical.center,
    this.alignment = Alignment.center,
    this.padding,
    this.style,
  }) : super(key: key);
  final Widget? suffixIcon;
  final Widget? prefixIcon;
  final String hintText;
  final bool? obscureText;
  final int? maxLength;
  final double? height;
  final TextInputType? keyboardType;
  final TextEditingController? controller;
  final double? prefixWidth;
  final Color? backgroundColor;
  final BorderRadius? borderRadius;
  final Border? border;
  final List<TextInputFormatter>? inputFormatters;
  final TextAlignVertical align;
  final Alignment alignment;
  final EdgeInsets? padding;
  final TextStyle? style;
  @override
  Widget build(BuildContext context) {
    return Container(
      height: height ?? 50.r,
      alignment: alignment,
      padding: prefixIcon != null
          ? EdgeInsets.zero
          : padding ?? EdgeInsets.symmetric(horizontal: 10.r),
      decoration: BoxDecoration(
        color: backgroundColor,
        borderRadius:
            border == null ? null : borderRadius ?? BorderRadius.circular(4.r),
        border: border ??
            const Border(
                bottom: BorderSide(color: ColorsUtil.separator, width: 1)),
      ),
      child: TextField(
        controller: controller,
        maxLength: maxLength,
        obscureText: obscureText ?? false,
        keyboardType: keyboardType,
        textAlignVertical: align,
        inputFormatters: inputFormatters,
        style: style,
        decoration: InputDecoration(
          isCollapsed: true,
          counterText: '',
          prefixIcon: prefixIcon == null
              ? null
              : Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    SizedBox(
                      width: prefixWidth,
                      child: prefixIcon,
                    )
                  ],
                ),
          suffixIcon: suffixIcon,
          hintText: hintText,
          hintStyle:
              pfMediumStyle(color: ColorsUtil.placeholder, fontSize: 15.sp),
          enabledBorder: InputBorder.none,
          disabledBorder: InputBorder.none,
          focusedBorder: InputBorder.none,
        ),
      ),
    );
  }
}
